function X = winsorize(X,WinsorLevel)
[~,K]=size(X);
for k = 1:K
    Xk = X(:,k);
    Nt=sum(isfinite(Xk));
    if Nt>0
        Xs = sort(Xk);
        Nlo = round(Nt*WinsorLevel); if (Nlo==0); Nlo=1; end; X(X(:,k)<Xs(Nlo),k)=Xs(Nlo);
        Nhi = round(Nt*(1-WinsorLevel)); if (Nhi==0); Nhi=1; end; X(X(:,k)>Xs(Nhi),k)=Xs(Nhi);
    end
end
return